{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to atomman: Settings and Library\n",
    "\n",
    "__Lucas M. Hale__, [lucas.hale@nist.gov](mailto:lucas.hale@nist.gov?Subject=ipr-demo), _Materials Science and Engineering Division, NIST_.\n",
    "    \n",
    "[Disclaimers](http://www.nist.gov/public_affairs/disclaimer.cfm) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Introduction<a id='section1'></a>\n",
    "\n",
    "*Added version 1.3.3*\n",
    "\n",
    "The atomman package inherits Settings and Library from the [potentials package](https://github.com/usnistgov/potentials). The associated classes can be used to manage interactions with the NIST potentials reference library."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Library Imports**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "atomman version = 1.3.7\n",
      "Notebook executed on 2021-02-19\n"
     ]
    }
   ],
   "source": [
    "# Standard libraries\n",
    "from pathlib import Path\n",
    "import datetime       \n",
    "\n",
    "# https://github.com/usnistgov/atomman\n",
    "import atomman as am            \n",
    "\n",
    "# Show atomman version\n",
    "print('atomman version =', am.__version__)\n",
    "\n",
    "# Show date of Notebook execution\n",
    "print('Notebook executed on', datetime.date.today())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Settings<a id='section2'></a>\n",
    "\n",
    "The atomman.Settings class is a shortcut to the potentials.Settings class.  This allows for atomman, potentials, and iprPy to all share the same settings and local reference library."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<potentials.Settings.Settings object at 0x0000011DB1FEEB88>\n"
     ]
    }
   ],
   "source": [
    "settings = am.Settings()\n",
    "\n",
    "# Show that atomman.Settings == potentials.Settings\n",
    "print(repr(settings))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1. Set directory locations\n",
    "\n",
    "- __directory__ is the location where the settings.json file is to be found.  The default directory is .NISTpotentials in the user's home directory.  This can be changed with Settings.set_directory(), but should only be done if multiple users/environments with different home directories are sharing settings.\n",
    "\n",
    "- __library_directory__ is the location where the local library of reference records is located.  By default, this is inside the directory above.  It is recommended that it be set to somewhere more accessible if you wish to examine, modify or add to the reference records."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Settings directory is C:\\Users\\lmh1\\.NISTpotentials\n",
      "Library directory is C:\\Users\\lmh1\\Documents\\library\n"
     ]
    }
   ],
   "source": [
    "print('Settings directory is', settings.directory)\n",
    "print('Library directory is', settings.library_directory)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Settings directory is C:\\Users\\lmh1\\.NISTpotentials\n",
      "Library directory is C:\\Users\\lmh1\\Documents\\library\n"
     ]
    }
   ],
   "source": [
    "# Change the settings directory - Not recommended\n",
    "#settings.set_directory(<PATH>)\n",
    "\n",
    "# Change the library directory - Recommended\n",
    "#settings.set_library_directory(<PATH>)\n",
    "\n",
    "print('Settings directory is', settings.directory)\n",
    "print('Library directory is', settings.library_directory)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2. Set default database parameters\n",
    "\n",
    "- __local__ indicates the default value for the local parameter to use when initializing a Library object (below), with a value of True indicating that the local library directory will be searched for matching records.\n",
    "\n",
    "- __remote__ indicates the default value for the remote parameter to use when initializing a Library object (below), with a value of True indicating that the remote database https://potentials.nist.gov/ will be searched for matching records."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Default local parameter is True\n",
      "Default remote parameter is True\n"
     ]
    }
   ],
   "source": [
    "print('Default local parameter is', settings.local)\n",
    "print('Default remote parameter is', settings.remote)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Default local parameter is True\n",
      "Default remote parameter is True\n"
     ]
    }
   ],
   "source": [
    "# Change the local and remote parameters\n",
    "#settings.set_local(True)\n",
    "#settings.set_remote(False)\n",
    "\n",
    "print('Default local parameter is', settings.local)\n",
    "print('Default remote parameter is', settings.remote)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Database interface <a id='section3'></a>\n",
    "\n",
    "The atomman.library.Database class is a subclass of potentials.Database and extends it to provide support for crystal structure references in addition to the potentials references.  The class is used by atomman.load() for ['prototype'](1.4.10._prototype_loading.html) and ['crystal'](1.4.11._crystal_loading.html) styles and by [atomman.load_lammps_potential](2.1._Potential_class.html).  The class can also be directly accessed and used to explore the database for more involved investigations.\n",
    "\n",
    "See the documentation notebooks for the [potentials package](https://github.com/usnistgov/potentials) for more details on interacting with the potentials records."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1. Initialize a Database object\n",
    "\n",
    "\n",
    "Access parameters. Only change these if you are accessing an alternate database and/or have permission to add content.\n",
    "\n",
    "- __host__ (*str, optional*) CDCS site to access.  Default value is 'https://potentials.nist.gov/'.\n",
    "- __username__ (*str, optional*) User name to use to access the host site.  Default value of '' will access the site as an anonymous visitor.\n",
    "- __password__ (*str, optional*) Password associated with the given username.  Not needed for anonymous access.\n",
    "- __certification__ (*str, optional*) File path to certification file if needed for host.\n",
    "\n",
    "\n",
    "Settings options. These allow the default settings from above to be overridden.\n",
    "\n",
    "- __localpath__ (*str, optional*) Path to the local library directory to use.  If not given, will use the set library_directory setting.\n",
    "- __local__ (*bool, optional*) Indicates if the load operations will check localpath for records. Default value is controlled by settings.\n",
    "- __remote__ (*bool, optional*) Indicates if the load operations will download records from the remote database.  Default value is controlled by settings.  If a local copy exists, then setting this to False is considerably faster.\n",
    "\n",
    "Other options\n",
    "\n",
    "- __verbose__ (*bool, optional*) If True, info messages will be printed during operations.  Default value is False.\n",
    "- __load__ (*bool, str or list, optional*) If True, citations, potentials and lammps_potentials will all be loaded during initialization. If False (default), none will be loaded.  Alternatively, a str or list can be given to specify which of the three record types to load.\n",
    "- __status__ (*str, list or None, optional*) Only potential_LAMMPS records with the given status(es) will be loaded.  Allowed values are 'active' (default), 'superseded', and 'retracted'.  If None is given, then all potentials will be loaded."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "localpath = C:\\Users\\lmh1\\Documents\\library\n",
      "local = True\n",
      "remote = True\n"
     ]
    }
   ],
   "source": [
    "# Load Database with default settings \n",
    "potdb = am.library.Database()\n",
    "print('localpath =', potdb.localpath)\n",
    "print('local =', potdb.local)\n",
    "print('remote =', potdb.remote)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2. Exploring crystal prototypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.2.1. Load crystal prototypes\n",
    "\n",
    "The current prototypes in the local and/or remote database can be loaded into memory using the load_crystal_prototypes() method.\n",
    "\n",
    "- __localpath__ (*str, optional*) Path to a local directory to check for records first.  If not given, will check localpath value set during object initialization.  If not given or set during initialization, then only the remote database will be loaded.\n",
    "- __local__ (*bool, optional*) Indicates if records in localpath are to be loaded.  If not given, will use the local value set during initialization.\n",
    "- __remote__ (*bool, optional*) Indicates if the records in the remote database are to be loaded. Setting this to be False is useful/faster if a local copy of the database exists.  If not given, will use the local value set during initialization.\n",
    "- __verbose__ (*bool, optional*) If True, info messages will be printed during operations.  Default value is False."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded 19 local crystal prototypes\n",
      "Loaded 19 remote crystal prototypes\n",
      " - 0 new\n"
     ]
    }
   ],
   "source": [
    "potdb.load_crystal_prototypes(verbose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.2.2. Get crystal prototype(s) \n",
    "\n",
    "The get_crystal_prototype() and get_crystal_prototypes() methods can be used to find one or all crystal prototypes that match the given parameters. \n",
    "\n",
    "Note that how the get methods work depends on if the associated records have been loaded.  If not loaded, then the get methods will query the remote database.  If loaded, then the get methods will search the set of loaded local+remote entries.  The two variations should, but are not guaranteed, to behave identically. \n",
    "\n",
    "- __id__ (*str or list, optional*) Prototype ID(s) to search for.  These are unique identifiers for each prototype based on comm.\n",
    "- __key__ (*str or list, optional*) UUID4 key(s) to search for.  Each entry has a unique random-generated UUID4 key.\n",
    "- __name__ (*str or list, optional*) Common name(s) to limit the search by.\n",
    "- __prototype__ (*str or list, optional*) Prototype identifying composition(s) to limit the search by.\n",
    "- __pearson__ (*str or list, optional*) The Pearson symbol(s) to limit the search by.\n",
    "- __strukturbericht__ (*str or list, optional*) The strukturbericht identifier(s) to limit the search by.\n",
    "- __sg_number__ (*int or list, optional*) The space group number(s) to limit the search by.\n",
    "- __sg_hm__ (*str or list, optional*) The space group Hermann-Maguin identifier(s) to limit the search by.\n",
    "- __sg_schoenflies__ (*str or list, optional*) The space group Schoenflies identifier(s) to limit the search by.\n",
    "- __keyword__ (*str, optional*) If given, will limit the search to all records that contain the keyword substring.  Cannot be combined with any of the above parameters.\n",
    "- __verbose__ (*bool, optional*) If True, info messages will be printed during operations.  Default value is False.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Multiple matching crystal prototypes found.\n",
      "1 A3'--alpha-La--double-hcp\n",
      "2 A3--Mg--hcp\n",
      "Select which one: 2\n"
     ]
    }
   ],
   "source": [
    "prototype = potdb.get_crystal_prototype(keyword='hcp')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The returned CrystalPrototype object(s) have attributes associated with their metadata information as well as an atomman.System of the unit cell."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A3--Mg--hcp\n",
      "avect =  [ 1.000,  0.000,  0.000]\n",
      "bvect =  [-0.500,  0.866,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  1.633]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 2\n",
      "natypes = 1\n",
      "symbols = (None,)\n",
      "pbc = [ True  True  True]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   0.000 |   0.000 |   0.000\n",
      "      1 |       1 |   0.000 |   0.577 |   0.816\n"
     ]
    }
   ],
   "source": [
    "print(prototype.id)\n",
    "print(prototype.ucell)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.2.3. download_crystal_prototypes\n",
    "\n",
    "The download_crystal_prototypes method will download all entries in the remote to the local.\n",
    "\n",
    "- __localpath__ (*path-like object, optional*) Path to a local directory where the files will be saved to.  If not given, will use the localpath value set during object initialization.\n",
    "- __prototypes__ (*list of CrystalPrototype, optional*) A list of crystal prototypes to download. If not given, all prototypes will be downloaded.\n",
    "- __format__ (*str, optional*) The file format to save the record files as.  Allowed values are 'xml' and 'json' (default).\n",
    "- __indent__ (*int, optional*) The indentation spacing size to use for the locally saved record files. If not given, the JSON/XML content will be compact.\n",
    "- __verbose__ (*bool, optional*) If True, info messages will be printed during operations.  Default value is False."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#potdb.download_crystal_prototypes(format='json', indent=4, verbose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.2.4. crystal_prototypes and crystal_prototypes_df\n",
    "\n",
    "Calling load_crystal_prototypes builds crystal_prototypes, a numpy array containing all CrystalPrototype objects, and crystal_prototypes_df, a pandas DataFrame of the prototype metadata.  Combined, these allow for more involved custom explorations of the loaded prototypes. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key</th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>prototype</th>\n",
       "      <th>pearson</th>\n",
       "      <th>strukturbericht</th>\n",
       "      <th>sg_number</th>\n",
       "      <th>sg_hm</th>\n",
       "      <th>sg_schoenflies</th>\n",
       "      <th>ucell</th>\n",
       "      <th>crystal_family</th>\n",
       "      <th>natypes</th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "      <th>alpha</th>\n",
       "      <th>beta</th>\n",
       "      <th>gamma</th>\n",
       "      <th>natoms</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>d30980ad-ae18-425d-84cb-abf08577bdc8</td>\n",
       "      <td>A1--Cu--fcc</td>\n",
       "      <td>face-centered cubic</td>\n",
       "      <td>Cu</td>\n",
       "      <td>cF4</td>\n",
       "      <td>A1</td>\n",
       "      <td>225</td>\n",
       "      <td>F m -3 m</td>\n",
       "      <td>Oh^5</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>f4101896-1e17-4736-a4d1-308b8934e8ce</td>\n",
       "      <td>A15--Cr3Si</td>\n",
       "      <td>beta-tungsten</td>\n",
       "      <td>Cr3Si</td>\n",
       "      <td>cP8</td>\n",
       "      <td>A15</td>\n",
       "      <td>223</td>\n",
       "      <td>P m -3 n</td>\n",
       "      <td>Oh^3</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>e0126715-c7db-4d79-be80-707c572bebd6</td>\n",
       "      <td>A15--beta-W</td>\n",
       "      <td>beta-tungsten</td>\n",
       "      <td>b-W</td>\n",
       "      <td>cP8</td>\n",
       "      <td>A15</td>\n",
       "      <td>223</td>\n",
       "      <td>P m -3 n</td>\n",
       "      <td>Oh^3</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>bc13827d-e1e6-4d70-8c3a-59399ad78b0f</td>\n",
       "      <td>A2--W--bcc</td>\n",
       "      <td>body-centered cubic</td>\n",
       "      <td>W</td>\n",
       "      <td>cI2</td>\n",
       "      <td>A2</td>\n",
       "      <td>229</td>\n",
       "      <td>I m -3 m</td>\n",
       "      <td>Oh^9</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>154d1a2b-04da-4477-8962-a0ca0c17c8fc</td>\n",
       "      <td>A3'--alpha-La--double-hcp</td>\n",
       "      <td>double hcp</td>\n",
       "      <td>La</td>\n",
       "      <td>hP4</td>\n",
       "      <td>A3'</td>\n",
       "      <td>194</td>\n",
       "      <td>P 6_3/m m c</td>\n",
       "      <td>D6h^4</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [-...</td>\n",
       "      <td>hexagonal</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.265986</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>4dab7fbb-108a-425e-8adb-d55de7b1134b</td>\n",
       "      <td>A3--Mg--hcp</td>\n",
       "      <td>hexagonal close-packed</td>\n",
       "      <td>Mg</td>\n",
       "      <td>hP2</td>\n",
       "      <td>A3</td>\n",
       "      <td>194</td>\n",
       "      <td>P 6_3/m m c</td>\n",
       "      <td>D6h^4</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [-...</td>\n",
       "      <td>hexagonal</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.632993</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>12654c83-c153-4b58-8805-f6dce43b7842</td>\n",
       "      <td>A4--C--dc</td>\n",
       "      <td>diamond cubic</td>\n",
       "      <td>C</td>\n",
       "      <td>cF8</td>\n",
       "      <td>A4</td>\n",
       "      <td>227</td>\n",
       "      <td>F d -3 m</td>\n",
       "      <td>Oh^7</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>821526c5-561e-4f09-8a04-680419dc1495</td>\n",
       "      <td>A5--beta-Sn</td>\n",
       "      <td>white tin</td>\n",
       "      <td>b-Sn</td>\n",
       "      <td>tI4</td>\n",
       "      <td>A5</td>\n",
       "      <td>141</td>\n",
       "      <td>I 4_1/a m d</td>\n",
       "      <td>D4h^19</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>tetragonal</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.550000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>76cbf2c1-fa86-41c4-85ae-c24f55c9f13a</td>\n",
       "      <td>A6--In--bct</td>\n",
       "      <td>body-centered tetragonal</td>\n",
       "      <td>In</td>\n",
       "      <td>tI2</td>\n",
       "      <td>A6</td>\n",
       "      <td>139</td>\n",
       "      <td>I 4/m m m</td>\n",
       "      <td>D4h^17</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>tetragonal</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.500000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>c1e15cf8-6998-40ce-afbd-0b1cb6271a1f</td>\n",
       "      <td>A7--alpha-As</td>\n",
       "      <td>alpha As</td>\n",
       "      <td>a-As</td>\n",
       "      <td>hR6</td>\n",
       "      <td>A7</td>\n",
       "      <td>166</td>\n",
       "      <td>R -3 m</td>\n",
       "      <td>D3d^5</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [-...</td>\n",
       "      <td>hexagonal</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.777000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>ceb6d7cc-b20e-4878-8b2b-1e62185d16af</td>\n",
       "      <td>Ah--alpha-Po--sc</td>\n",
       "      <td>simple cubic</td>\n",
       "      <td>a-Po</td>\n",
       "      <td>cP1</td>\n",
       "      <td>Ah</td>\n",
       "      <td>221</td>\n",
       "      <td>P m -3 m</td>\n",
       "      <td>Oh^1</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>133ca871-c927-4073-ae46-b8a27e035f4b</td>\n",
       "      <td>B1--NaCl--rock-salt</td>\n",
       "      <td>rock salt</td>\n",
       "      <td>NaCl</td>\n",
       "      <td>cF8</td>\n",
       "      <td>B1</td>\n",
       "      <td>225</td>\n",
       "      <td>F m -3 m</td>\n",
       "      <td>Oh^5</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>7398b231-fd55-4378-b6b2-6607262d3090</td>\n",
       "      <td>B2--CsCl</td>\n",
       "      <td>cesium chloride</td>\n",
       "      <td>CsCl</td>\n",
       "      <td>cP2</td>\n",
       "      <td>B2</td>\n",
       "      <td>221</td>\n",
       "      <td>P m -3 m</td>\n",
       "      <td>Oh^1</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>ce517a32-6bca-47d0-82a2-2ee48956cff9</td>\n",
       "      <td>B3--ZnS--cubic-zinc-blende</td>\n",
       "      <td>cubic zinc-blende</td>\n",
       "      <td>c-ZnS</td>\n",
       "      <td>cF8</td>\n",
       "      <td>B3</td>\n",
       "      <td>216</td>\n",
       "      <td>F -4 3 m</td>\n",
       "      <td>Td^2</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>74171ba0-6605-4956-b8d5-0059672ee7e2</td>\n",
       "      <td>C1--CaF2--fluorite</td>\n",
       "      <td>fluorite</td>\n",
       "      <td>CaF2</td>\n",
       "      <td>cF12</td>\n",
       "      <td>C1</td>\n",
       "      <td>225</td>\n",
       "      <td>F m -3 m</td>\n",
       "      <td>Oh^5</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>8a2eb4b8-1302-46d9-992d-4296c227d966</td>\n",
       "      <td>D0_3--BiF3</td>\n",
       "      <td>BiF3</td>\n",
       "      <td>BiF3</td>\n",
       "      <td>cF16</td>\n",
       "      <td>D0_3</td>\n",
       "      <td>225</td>\n",
       "      <td>F m -3 m</td>\n",
       "      <td>Oh^5</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>f7b8d5d9-b0eb-401a-9cc3-038170e3ac1c</td>\n",
       "      <td>L1_0--AuCu</td>\n",
       "      <td>AuCu</td>\n",
       "      <td>AuCu</td>\n",
       "      <td>tP2</td>\n",
       "      <td>L1_0</td>\n",
       "      <td>123</td>\n",
       "      <td>P 4/m m m</td>\n",
       "      <td>D4h^1</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>tetragonal</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.309600</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>942ce385-85ab-4cb9-8adc-4bdaaf145831</td>\n",
       "      <td>L1_2--AuCu3</td>\n",
       "      <td>AuCu3</td>\n",
       "      <td>AuCu3</td>\n",
       "      <td>cP4</td>\n",
       "      <td>L1_2</td>\n",
       "      <td>221</td>\n",
       "      <td>P m -3 m</td>\n",
       "      <td>Oh^1</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>0fb6d590-5ce5-4476-a1bf-7130f96f2af1</td>\n",
       "      <td>L2_1--AlCu2Mn--heusler</td>\n",
       "      <td>heusler</td>\n",
       "      <td>AlCu2Mn</td>\n",
       "      <td>cF16</td>\n",
       "      <td>L2_1</td>\n",
       "      <td>225</td>\n",
       "      <td>F m -3 m</td>\n",
       "      <td>Oh^5</td>\n",
       "      <td>avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...</td>\n",
       "      <td>cubic</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     key                          id  \\\n",
       "0   d30980ad-ae18-425d-84cb-abf08577bdc8                 A1--Cu--fcc   \n",
       "2   f4101896-1e17-4736-a4d1-308b8934e8ce                  A15--Cr3Si   \n",
       "1   e0126715-c7db-4d79-be80-707c572bebd6                 A15--beta-W   \n",
       "3   bc13827d-e1e6-4d70-8c3a-59399ad78b0f                  A2--W--bcc   \n",
       "4   154d1a2b-04da-4477-8962-a0ca0c17c8fc   A3'--alpha-La--double-hcp   \n",
       "5   4dab7fbb-108a-425e-8adb-d55de7b1134b                 A3--Mg--hcp   \n",
       "6   12654c83-c153-4b58-8805-f6dce43b7842                   A4--C--dc   \n",
       "7   821526c5-561e-4f09-8a04-680419dc1495                 A5--beta-Sn   \n",
       "8   76cbf2c1-fa86-41c4-85ae-c24f55c9f13a                 A6--In--bct   \n",
       "9   c1e15cf8-6998-40ce-afbd-0b1cb6271a1f                A7--alpha-As   \n",
       "10  ceb6d7cc-b20e-4878-8b2b-1e62185d16af            Ah--alpha-Po--sc   \n",
       "11  133ca871-c927-4073-ae46-b8a27e035f4b         B1--NaCl--rock-salt   \n",
       "12  7398b231-fd55-4378-b6b2-6607262d3090                    B2--CsCl   \n",
       "13  ce517a32-6bca-47d0-82a2-2ee48956cff9  B3--ZnS--cubic-zinc-blende   \n",
       "14  74171ba0-6605-4956-b8d5-0059672ee7e2          C1--CaF2--fluorite   \n",
       "15  8a2eb4b8-1302-46d9-992d-4296c227d966                  D0_3--BiF3   \n",
       "16  f7b8d5d9-b0eb-401a-9cc3-038170e3ac1c                  L1_0--AuCu   \n",
       "17  942ce385-85ab-4cb9-8adc-4bdaaf145831                 L1_2--AuCu3   \n",
       "18  0fb6d590-5ce5-4476-a1bf-7130f96f2af1      L2_1--AlCu2Mn--heusler   \n",
       "\n",
       "                        name prototype pearson strukturbericht  sg_number  \\\n",
       "0        face-centered cubic        Cu     cF4              A1        225   \n",
       "2              beta-tungsten     Cr3Si     cP8             A15        223   \n",
       "1              beta-tungsten       b-W     cP8             A15        223   \n",
       "3        body-centered cubic         W     cI2              A2        229   \n",
       "4                 double hcp        La     hP4             A3'        194   \n",
       "5     hexagonal close-packed        Mg     hP2              A3        194   \n",
       "6              diamond cubic         C     cF8              A4        227   \n",
       "7                  white tin      b-Sn     tI4              A5        141   \n",
       "8   body-centered tetragonal        In     tI2              A6        139   \n",
       "9                   alpha As      a-As     hR6              A7        166   \n",
       "10              simple cubic      a-Po     cP1              Ah        221   \n",
       "11                 rock salt      NaCl     cF8              B1        225   \n",
       "12           cesium chloride      CsCl     cP2              B2        221   \n",
       "13         cubic zinc-blende     c-ZnS     cF8              B3        216   \n",
       "14                  fluorite      CaF2    cF12              C1        225   \n",
       "15                      BiF3      BiF3    cF16            D0_3        225   \n",
       "16                      AuCu      AuCu     tP2            L1_0        123   \n",
       "17                     AuCu3     AuCu3     cP4            L1_2        221   \n",
       "18                   heusler   AlCu2Mn    cF16            L2_1        225   \n",
       "\n",
       "          sg_hm sg_schoenflies  \\\n",
       "0      F m -3 m           Oh^5   \n",
       "2      P m -3 n           Oh^3   \n",
       "1      P m -3 n           Oh^3   \n",
       "3      I m -3 m           Oh^9   \n",
       "4   P 6_3/m m c          D6h^4   \n",
       "5   P 6_3/m m c          D6h^4   \n",
       "6      F d -3 m           Oh^7   \n",
       "7   I 4_1/a m d         D4h^19   \n",
       "8     I 4/m m m         D4h^17   \n",
       "9        R -3 m          D3d^5   \n",
       "10     P m -3 m           Oh^1   \n",
       "11     F m -3 m           Oh^5   \n",
       "12     P m -3 m           Oh^1   \n",
       "13     F -4 3 m           Td^2   \n",
       "14     F m -3 m           Oh^5   \n",
       "15     F m -3 m           Oh^5   \n",
       "16    P 4/m m m          D4h^1   \n",
       "17     P m -3 m           Oh^1   \n",
       "18     F m -3 m           Oh^5   \n",
       "\n",
       "                                                ucell crystal_family  natypes  \\\n",
       "0   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        1   \n",
       "2   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        2   \n",
       "1   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        1   \n",
       "3   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        1   \n",
       "4   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [-...      hexagonal        1   \n",
       "5   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [-...      hexagonal        1   \n",
       "6   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        1   \n",
       "7   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...     tetragonal        1   \n",
       "8   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...     tetragonal        1   \n",
       "9   avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [-...      hexagonal        1   \n",
       "10  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        1   \n",
       "11  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        2   \n",
       "12  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        2   \n",
       "13  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        2   \n",
       "14  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        2   \n",
       "15  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        2   \n",
       "16  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...     tetragonal        2   \n",
       "17  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        2   \n",
       "18  avect =  [ 1.000,  0.000,  0.000]\\nbvect =  [ ...          cubic        3   \n",
       "\n",
       "      a    b         c  alpha  beta  gamma  natoms  \n",
       "0   1.0  1.0  1.000000   90.0  90.0   90.0       4  \n",
       "2   1.0  1.0  1.000000   90.0  90.0   90.0       8  \n",
       "1   1.0  1.0  1.000000   90.0  90.0   90.0       8  \n",
       "3   1.0  1.0  1.000000   90.0  90.0   90.0       2  \n",
       "4   1.0  1.0  3.265986   90.0  90.0  120.0       4  \n",
       "5   1.0  1.0  1.632993   90.0  90.0  120.0       2  \n",
       "6   1.0  1.0  1.000000   90.0  90.0   90.0       8  \n",
       "7   1.0  1.0  0.550000   90.0  90.0   90.0       4  \n",
       "8   1.0  1.0  1.500000   90.0  90.0   90.0       2  \n",
       "9   1.0  1.0  2.777000   90.0  90.0  120.0       6  \n",
       "10  1.0  1.0  1.000000   90.0  90.0   90.0       1  \n",
       "11  1.0  1.0  1.000000   90.0  90.0   90.0       8  \n",
       "12  1.0  1.0  1.000000   90.0  90.0   90.0       2  \n",
       "13  1.0  1.0  1.000000   90.0  90.0   90.0       8  \n",
       "14  1.0  1.0  1.000000   90.0  90.0   90.0      12  \n",
       "15  1.0  1.0  1.000000   90.0  90.0   90.0      16  \n",
       "16  1.0  1.0  1.309600   90.0  90.0   90.0       2  \n",
       "17  1.0  1.0  1.000000   90.0  90.0   90.0       4  \n",
       "18  1.0  1.0  1.000000   90.0  90.0   90.0      16  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Display the metadata for all prototypes\n",
    "potdb.crystal_prototypes_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A5--beta-Sn\n",
      "A6--In--bct\n",
      "L1_0--AuCu\n"
     ]
    }
   ],
   "source": [
    "# Find the listings in df that are tetragonal\n",
    "is_tetragonal = potdb.crystal_prototypes_df.crystal_family == 'tetragonal'\n",
    "\n",
    "# Use is_tetragonal mask to retrieve the associated prototypes\n",
    "for prototype in potdb.crystal_prototypes[is_tetragonal]:\n",
    "    print(prototype.id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3. Exploring relaxed crystals\n",
    "\n",
    "The Database object has built-in methods for exploring the relaxed crystals in a similar manner as the crystal prototypes:\n",
    "\n",
    "- load_relaxed_crystals() builds listings for all relaxed crystals from local and/or remote\n",
    "- relaxed_crystals and relaxed_crystals_df are the listings built by load_relaxed_crystals()\n",
    "- get_relaxed_crystals() and get_relaxed_crystal() retrieve matching entries\n",
    "- download_relaxed_crystals() downloads all remote entries to local\n",
    "\n",
    "__HOWEVER__, many of these operations are incredibly slow due to the large number of relaxed crystal entries.  There are two suggested methods to best reduce the processing time, which are listed below."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.3.1. Remote-only searches\n",
    "\n",
    "The simplest method is to call get_relaxed_crystals() or get_relaxed_crystal() without calling load_relaxed_crystals().  This will send queries to the remote database to retrieve matching records.  Giving parameters that limit the search to as few entries as possible will reduce the amount of information that needs to be downloaded. \n",
    "\n",
    "Limitations: Requires internet access, no user-defined local entries will be included, and each search involves a separate internet request.\n",
    "\n",
    "Parameters for get_relaxed_crystals and get_relaxed_crystal\n",
    "\n",
    "- __key__ (*str or list, optional*) UUID4 key(s) to search for.  Each entry has a unique random-generated UUID4 key.\n",
    "- __method__ (*str or list or None, optional*) The relaxation method used.  Allowed values are dynamic, static and box. Default value is dynamic (the most rigorous relaxation method).  All will be loaded if set to None.\n",
    "- __standing__ (*str or list or None, optional*) \"good\" records are the unique crystals found with the most rigorous relaxation, and with known prototypes over DFT structures.  \"bad\" are records filtered out, usually for being duplicates.  Default value is \"good\".  All will be loaded if set to None.\n",
    "- __family__ (*str or atomman.library.CrystalPrototype or list, optional*) The crystal family associated with the relaxed crystal - either crystal prototype name or MP/OQMD database entry name.\n",
    "- __parent_key__ (*str or list, optional*) The UUID4 key(s) assigned to the calculation that the record is based on.\n",
    "- __potential__ (*atomman.lammps.Potential or list, optional*) A loaded LAMMPS potential object to limit the search by.\n",
    "- __potential_LAMMPS_id__ (*str or list, optional*) The id for a LAMMPS implemented potential to limit the search by.\n",
    "- __potential_LAMMPS_key__ (*str or list, optional*) The UUID4 for a LAMMPS implemented potential to limit the search by.\n",
    "- __potential_id__ (*str or list, optional*) The id for a potential to limit the search by.\n",
    "- __potential_key__ (*str or list, optional*) The UUID4 for a potential to limit the search by.\n",
    "- __symbols__ (*str or list, optional*) Element symbols in the crystal to limit the search by.\n",
    "- __natypes__ (*int or list, optional*) The number of unique element model symbols in the crystal to limit the search by.\n",
    "- __natoms__ (*int or list, optional*) The number of unique atoms in the crystal's unit cell to limit the search by.\n",
    "- __keyword__ (*str, optional*) If given, will limit the search to all records that contain the keyword substring.  Cannot be combined with any of the above parameters.\n",
    "- __verbose__ (*bool, optional*) If True, info messages will be printed during operations.  Default value is False."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alat    Ecoh   potential_LAMMPS_id\n",
      "4.0685 -4.2994 2012--Norman-G-E--Au--LAMMPS--ipr1\n",
      "4.0801 -3.9300 2004--Zhou-X-W--Cu-Ag-Au--LAMMPS--ipr2\n",
      "4.0801 -3.9300 2004--Zhou-X-W--Au--LAMMPS--ipr2\n",
      "4.0801 -3.9300 2004--Zhou-X-W--Cu-Ag-Au--LAMMPS--ipr1\n",
      "4.0798 -3.9300 2004--Zhou-X-W--Au--LAMMPS--ipr1\n",
      "4.0800 -3.9300 1986--Foiles-S-M--Au--LAMMPS--ipr1\n",
      "4.0800 -3.9300 1986--Foiles-S-M--Ag-Au-Cu-Ni-Pd-Pt--LAMMPS--ipr1\n",
      "4.0780 -3.9300 2017--Purja-Pun-G-P--Au--LAMMPS--ipr1\n",
      "4.0800 -3.9300 1989--Adams-J-B--Au--LAMMPS--ipr1\n",
      "4.0800 -3.9300 1989--Adams-J-B--Ag-Au-Cu-Ni-Pd-Pt--LAMMPS--ipr1\n",
      "4.0701 -3.9242 2005--Grochola-G--Au--LAMMPS--ipr1\n",
      "4.1820 -3.9024 2018--Starikov-S-V--Si-Au--LAMMPS--ipr1\n",
      "4.1820 -3.9024 2018--Starikov-S-V--Si-Au--LAMMPS--ipr2\n",
      "4.0800 -3.8100 2010--Olsson-P-A-T--Au--LAMMPS--ipr1\n",
      "4.0780 -3.7890 1987--Ackland-G-J--Au--LAMMPS--ipr2\n",
      "4.0780 -3.7890 1987--Ackland-G-J--Au--LAMMPS--ipr1\n",
      "4.1529 -3.0332 2017--OBrien-C-J--Pt-Au--LAMMPS--ipr1\n",
      "6.2107 -0.6133 2012--Norman-G-E--Au--LAMMPS--ipr1\n"
     ]
    }
   ],
   "source": [
    "# Fetch all records for fcc gold\n",
    "fcc_gold = potdb.get_relaxed_crystals(family='A1--Cu--fcc', symbols=['Au'])\n",
    "\n",
    "# List the matches, the a lattice constant and the associated potential\n",
    "print('alat    Ecoh   potential_LAMMPS_id')\n",
    "for crystal in fcc_gold:\n",
    "    print(f'{crystal.ucell.box.a:.4f} {crystal.cohesive_energy:.4f} {crystal.potential_LAMMPS_id}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.3.2. Local-only searches\n",
    "\n",
    "The other recommended method is to load only records from the local and then perform the get searches. Doing this, of course, requires that any relaxed crystal records first be downloaded to the local library directory, which can be done one of two ways\n",
    "\n",
    "1. First performing a remote-only search as mentioned above, then passing the list of matching records as parameters to the download_relaxed_crystals() method.  This allows for records of interest to be saved for accessing later.\n",
    "\n",
    "2. If you want all available entries in the local copy, download or clone the git repository at https://github.com/lmhale99/potentials-library to the local library directory.  While all the entries can be downloaded using download_relaxed_crystals(), doing so is incredibly slow.\n",
    "\n",
    "Either way, once the crystal records are in the local directory they can be loaded with load_relaxed_crystals(remote=False), and then the get_relaxed_crystals() and get_relaxed_crystal() methods will work without needing internet access. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded 59326 local relaxed crystals\n"
     ]
    }
   ],
   "source": [
    "potdb.load_relaxed_crystals(remote=False, verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alat    Ecoh   potential_LAMMPS_id\n",
      "4.0800 -3.9300 1989--Adams-J-B--Ag-Au-Cu-Ni-Pd-Pt--LAMMPS--ipr1\n",
      "4.0800 -3.8100 2010--Olsson-P-A-T--Au--LAMMPS--ipr1\n",
      "7.8429 -0.8357 2020--Starikov-S--Si-Au-Al--LAMMPS--ipr1\n",
      "4.0701 -3.9242 2005--Grochola-G--Au--LAMMPS--ipr1\n",
      "4.0800 -3.9300 1986--Foiles-S-M--Au--LAMMPS--ipr1\n",
      "4.1820 -3.9024 2018--Starikov-S-V--Si-Au--LAMMPS--ipr1\n",
      "4.0685 -4.2994 2012--Norman-G-E--Au--LAMMPS--ipr1\n",
      "4.1499 -3.8612 2020--Starikov-S--Si-Au-Al--LAMMPS--ipr1\n",
      "4.0780 -3.9300 2017--Purja-Pun-G-P--Au--LAMMPS--ipr1\n",
      "4.1529 -3.0332 2017--OBrien-C-J--Pt-Au--LAMMPS--ipr1\n",
      "4.0801 -3.9300 2004--Zhou-X-W--Cu-Ag-Au--LAMMPS--ipr2\n",
      "4.0798 -3.9300 2004--Zhou-X-W--Au--LAMMPS--ipr1\n",
      "4.0800 -3.9300 1986--Foiles-S-M--Ag-Au-Cu-Ni-Pd-Pt--LAMMPS--ipr1\n",
      "4.0780 -3.7890 1987--Ackland-G-J--Au--LAMMPS--ipr1\n",
      "4.0780 -3.7890 1987--Ackland-G-J--Au--LAMMPS--ipr2\n",
      "4.0801 -3.9300 2004--Zhou-X-W--Au--LAMMPS--ipr2\n",
      "4.0800 -3.9300 1989--Adams-J-B--Au--LAMMPS--ipr1\n",
      "6.1962 -1.4338 2020--Starikov-S--Si-Au-Al--LAMMPS--ipr1\n",
      "6.2107 -0.6133 2012--Norman-G-E--Au--LAMMPS--ipr1\n",
      "4.0650 -3.8100 2009--Zhakhovskii-V-V--Au--LAMMPS--ipr2\n",
      "4.0801 -3.9300 2004--Zhou-X-W--Cu-Ag-Au--LAMMPS--ipr1\n",
      "4.1820 -3.9024 2018--Starikov-S-V--Si-Au--LAMMPS--ipr2\n"
     ]
    }
   ],
   "source": [
    "# Fetch all records for fcc gold\n",
    "fcc_gold = potdb.get_relaxed_crystals(family='A1--Cu--fcc', symbols=['Au'])\n",
    "\n",
    "# List the matches, the a lattice constant and the associated potential\n",
    "print('alat    Ecoh   potential_LAMMPS_id')\n",
    "for crystal in fcc_gold:\n",
    "    print(f'{crystal.ucell.box.a:.4f} {crystal.cohesive_energy:.4f} {crystal.potential_LAMMPS_id}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.4. Exploring potentials\n",
    "\n",
    "The Database object allows for searching potential entries by citation and searching lammps implementations of the potentials.\n",
    "\n",
    "Methods and attributes for exploring potential listings:\n",
    "\n",
    "- **widget_search_potentials** provides a Jupyter GUI for exploring potential entries.\n",
    "- **potentials** is a list of the entries as objects.  This is generated if load_potentials() is called.\n",
    "- **potentials_df** is a pandas.DataFrame containing the content of the listings.  This is generated if load_potentials() is called.\n",
    "- **load_potentials()** builds potentials and potentials_df based on entries found in the local and/or remote databases.\n",
    "- **get_potentials() and get_potential()** retrieves all potentials or one potential, respectively, that match with any given parameters. \n",
    "- **download_potentials** will download all potential entries from remote to local.  \n",
    "- **save_potentials** saves user-defined entries to local.\n",
    "- **upload_potential** uploads a new/updated potential listing to remote.  Requires write permission for the remote database.\n",
    "- **delete_potential** will delete a listing from local and/or remote (if permissions are allowed).\n",
    "\n",
    "Methods and attributes for exploring LAMMPS potential listings:\n",
    "\n",
    "- **widget_lammps_potential** provides a Jupyter GUI for exploring LAMMPS potential entries and retrieving any associated parameter files.\n",
    "- **lammps_potentials** is a list of the entries as objects.  This is generated if load_lammps_potentials() is called.\n",
    "- **lammps_potentials_df** is a pandas.DataFrame containing the content of the listings.  This is generated if load_lammps_potentials() is called.\n",
    "- **load_lammps_potentials** builds lammps_potentials and lammps_potentials_df based on entries found in the local and/or remote databases.\n",
    "- **get_lammps_potentials and get_lammps_potential** retrieves all LAMMPS potentials or one LAMMPS potential, respectively, that match with any given parameters. \n",
    "- **download_lammps_potentials** will download all LAMMPS potential entries from remote to local.\n",
    "- **get_lammps_potentials_files** will download any parameter files associated with one or more LAMMPS potentials to local.\n",
    "- **save_lammps_potentials** saves user-defined entries to local.\n",
    "- **upload_lammps_potential** uploads a new/updated LAMMPS potential listing to remote.  Requires write permission for the remote database.\n",
    "- **delete_lammps_potential** will delete a listing from local and/or remote (if permissions are allowed).\n",
    "\n",
    "See the documentation notebooks for the [potentials package](https://github.com/usnistgov/potentials) for more details on interacting with the potentials records."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
